package com.lcy.dao.impl;
import com.lcy.dao.SmbmsUserDao ;
import com.lcy.entry.SmbmsUser;

import java.sql.*;

public class SmbmsUserDaoImpl implements SmbmsUserDao{
    public SmbmsUser getSmbmsUserByUserCode(String userCodeParam) {
        try {

            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://127.0.0.1:3306/smbms?useUnicode=true&characterEncoding=utf-8";
            String userRoot = "root";
            String userPwd = "123456";
            Connection connection = DriverManager.getConnection(url, userRoot, userPwd);
            String sql = "select * from smbms_user where userCode ='" + userCodeParam + "'";
            PreparedStatement pst = connection.prepareStatement(sql);
            ResultSet resultSet = pst.executeQuery();
            SmbmsUser smbmsUser = null;
            while (resultSet.next()) {
                smbmsUser = new SmbmsUser();
                String userCode = resultSet.getString("userCode");
                String userName = resultSet.getString("userName");
                String userPassword = resultSet.getString("userPassword");
                smbmsUser.setUserCode(userCode);
                smbmsUser.setUserName(userName);
                smbmsUser.setUserPassword(userPassword);
            }
            return smbmsUser;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch(SQLException throwables){
            throwables.printStackTrace();
        }
        return null;
    }
}

